<template>
	<view class="transfer">
		<commonHeader :title="$t('at1')"></commonHeader>
		<view class="gHeadbox"></view>
		<view class="box">
			<view class="box_t">
				<view class="lang">

				</view>
				<view class="">
					{{ $t('at2') }}
				</view>
			</view>
			<view class="boxAddress">
				
				<view class="boxAddress_nadd" v-if="typeCher==1">
					{{ $t('at15') }}：
				</view>
				<view class="boxAddress_nadds" v-if="typeCher==1">
					<input type="text" v-model="numbers" :placeholder="$t('at4')" />
				</view>
				<view class="boxAddress_item">
					<view class="boxAddress_item_u">
						USDT：{{Number(maccount.usdt)}}
					</view>
					<!-- <view class="boxAddress_item_c" @click="typeCher=1">
						<view :class="typeCher==1?'check':'check checks'">

						</view>
						<text>{{ $t('at3') }}</text>
					</view> -->
					<!-- <view class="boxAddress_item_inp">
						<input type="text" v-model="numbers" v-if="typeCher==1" :placeholder="$t('at4')" />
					</view> -->
				</view>
				<!-- <view class="boxAddress_item">
					<view class="boxAddress_item_u">
						JUMP：{{Number(maccount.holderJump)}}
					</view>
					<view class="boxAddress_item_c" @click="typeCher=4">
						<view :class="typeCher==4?'check':'check checks'">

						</view>
						<text>{{ $t('at3') }}</text>
					</view>
					<view class="boxAddress_item_inp">
						<input type="text" v-model="numbers" v-if="typeCher==4" :placeholder="$t('at5')" />
					</view>
				</view> -->
				<view class="boxAddress_nadd">
					{{ $t('at6') }}：
				</view>
				<view class="boxAddress_nadds">
					<input type="text" v-model="toaddress" :placeholder="$t('at7')" />
				</view>
			</view>
			<view class="boxAddress">
				<view class="boxAddress_nadd">
					{{ $t('at8') }}：
				</view>
				<view class="boxAddress_nadds">
					<input type="password"  v-model="password" :placeholder="$t('at9')" />
				</view>
			</view>
			<view class="boxBtn" @click="fnMActivate">
				{{$t('at10')}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		memberAccount, //用户资产
		memberTransfer, //转账
		
	} from '@/api/home.js'
	export default {
		data() {
			return {
				typeCher: 1,
				password: '',
				numbers: '',
				toaddress: '',
				maccount:'',//用户资产
			}
		},
		mounted() {
			this.fnmemberAccount() // 用户资产
		},
		methods: {
			// 用户资产
			fnmemberAccount() {
				var params = {
					address: this.$store.state.devAddress
				}
				memberAccount(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.maccount = res.data
					}
				})
			},
			// 转账
			fnMActivate() {
				if (!this.numbers) {
					uni.showToast({
						icon: 'error',
						title: this.$t('at11'),
					})
					return;
				} else if (!this.toaddress) {
					uni.showToast({
						icon: 'error',
						title: this.$t('at12'),
					})
					return;
				} else if (!this.password) {
					uni.showToast({
						icon: 'error',
						title:this.$t('at13'),
					})
					return;
				}
				var params = {
					address: this.$store.state.devAddress,
					to: this.toaddress,
					type: this.typeCher,
					password: this.password,
					amount: this.numbers,
				}
				memberTransfer(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: this.$t('at14')
							// res.msg,
						})
						setTimeout(() => {
							console.log('888')
							// 返回上一页并发送事件通知
							uni.navigateBack({
								delta: 1, // 返回的页面数，如果需要返回上一页，delta 设为 1
								success: function() {
									// 通过 eventChannel 向上一页发送事件
									let pages = getCurrentPages();
									let prevPage = pages[pages.length - 2];
									prevPage.$vm.triggerRefresh();
								}
							});
						}, 2000)

					} else {
						uni.showToast({
							icon: 'error',
							title: res.msg,
						})
					}

				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.box {
		padding: 30rpx;
		box-sizing: border-box;

		&_t {
			display: flex;
			align-items: center;
			color: #ffffff;
			font-size: 30rpx;
			font-weight: 500;
			font-family: "苹方";
			margin-bottom: 50rpx;

			.lang {
				width: 6rpx;
				height: 30rpx;
				opacity: 1;
				border: 2rpx solid #979797;
				background: #d6a7f9;
				margin-right: 20rpx;
			}
		}

		.boxAddress {
			width: 100%;
			border-radius: 24rpx;
			opacity: 1;
			background: linear-gradient(137deg, #65008275 0%, #20005e63 100%);
			box-shadow: inset 0 2rpx 6rpx 0 #4545458a, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 20rpx 0 #00000038;
			padding: 30rpx 30rpx 40rpx;
			box-sizing: border-box;
			margin-bottom: 56rpx;

			&_item {
				display: flex;
				align-items: center;
				color: #ffffff;
				font-size: 30rpx;
				font-weight: 500;
				font-family: "苹方";
				margin-bottom: 40rpx;

				&_u {
					margin-right: 30rpx;
					width: 220rpx;
					margin-top: 10rpx;
				}

				&_c {
					display: flex;
					align-items: center;
					margin-right: 16rpx;

					.check {
						display: inline-block;
						position: relative;
						width: 28rpx;
						height: 28rpx;
						border-radius: 50%;
						background: linear-gradient(-16.5deg, #f1b8ff 0%, #e474ff 100%);
						margin-right: 8rpx;
					}

					.checks {
						background: #aaaaac;
					}

					.check::before,
					.check::after {
						content: '';
						pointer-events: none;
						position: absolute;
						color: white;
						border: 1px solid;
						background-color: white;
					}

					.check::before {
						width: 1px;
						height: 1px;
						left: 25%;
						top: 50%;
						transform: skew(0deg, 50deg);
					}

					.check::after {
						width: 3px;
						height: 1px;
						left: 45%;
						top: 42%;
						transform: skew(0deg, -50deg);
					}
				}

				&_inp {
					width: 250rpx;
					padding: 0 18rpx;
					box-sizing: border-box;

					input {
						border-bottom: 1rpx solid #b1b1b2;
					}
				}
			}

			&_nadd {
				color: #ffffff;
				font-size: 28rpx;
				font-weight: 900;
				font-family: "苹方";
				margin-bottom: 22rpx;
			}

			&_nadds {
				color: #ffffff;
				font-size: 24rpx;
				font-weight: 400;
				font-family: "苹方";
				border-bottom: 2rpx solid #b1b1b2;
				line-height: 60rpx;
				height: 60rpx;

				input {
					line-height: 60rpx;
				}

				::placeholder {

					color: #aaaaac;
					font-size: 24rpx;
					font-weight: 400;
					font-family: "苹方";
				}
			}
		}

		.boxBtn {
			background: url("@/static/img/w.png") no-repeat;
			background-size: cover;
			width: 572rpx;
			height: 78rpx;
			line-height: 78rpx;
			text-align: center;
			color: #ffffff;
			font-size: 42rpx;
			font-weight: 500;
			margin: 220rpx auto;

		}
	}
</style>